local qiongqing = fk.CreateSkill {
  name = "lingling__qiongqing",
}

Fk:loadTranslationTable {
  ["lingling__qiongqing"] = "穷青",
  [":lingling__qiongqing"] = "出牌阶段限两次，你可以重铸一张黑色牌，然后选择一张游戏外的<a href=':lingling__qiongqing_paintings'>画作</a>令一名角色获得（进入弃牌堆时销毁），若不为你，其交给你一张牌。",
  [":lingling__qiongqing_paintings"] = "<a href=':ling__shenxian_tu'><img src ='../../../lingling/image/card/ling__shenxian_tu.png'></img></a>"
      .. "&nbsp;<a href=':ling__jialing_tu'><img src ='../../../lingling/image/card/ling__jialing_tu.png'></img></a>"
      .. "&nbsp;<a href=':ling__weimo_tu'><img src ='../../../lingling/image/card/ling__weimo_tu.png'></img></a>"
      .. "&nbsp;<a href=':ling__songzi_tu'><img src ='../../../lingling/image/card/ling__songzi_tu.png'></img></a>"
      .. "&nbsp;<a href=':ling__diyu_tu'><img src ='../../../lingling/image/card/ling__diyu_tu.png'></img></a>"
      .. "<br><font color='Gray'>点击画作可查看技能",

  ["#lingling__qiongqing-active"] = "穷青：出牌阶段限两次，你可以重铸一张黑色牌，画一幅画。",
  ["#lingling__qiongqing-choose"] = "穷青：选择一副画作",
  ["#lingling__qiongqing-target"] = "穷青：选择一名角色，令其获得【%arg】",
  ["#lingling__qiongqing-give"] = "穷青：交给 %dest 一张牌",
}

local U = require "packages/utility/utility"

qiongqing:addEffect("active", {
  anim_type = "drawcard",
  prompt = "#lingling__qiongqing-active",
  can_use = function(self, player)
    return player:usedEffectTimes(self.name, Player.HistoryPhase) < 2
  end,
  times = function(self, player)
    return 2 - player:usedEffectTimes(self.name, Player.HistoryPhase)
  end,
  card_num = 1,
  card_filter = function(self, player, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).color == Card.Black
  end,
  target_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = effect.from
    room:recastCard(effect.cards, player, qiongqing.name)
    local cards = table.filter(U.prepareDeriveCards(room, {
      { "ling__shenxian_tu", Card.Spade, 13 },
      { "ling__jialing_tu",  Card.Spade, 13 },
      { "ling__weimo_tu",    Card.Spade, 13 },
      { "ling__songzi_tu",   Card.Spade, 13 },
      { "ling__diyu_tu",     Card.Spade, 13 }
    }, "qiongqing_derivecards"), function(id)
      return room:getCardArea(id) == Card.Void
    end)
    if #cards > 0 then
      local card = room:askToChooseCard(player, {
        skill_name = qiongqing.name,
        target = player,
        flag = {
          card_data = {
            { "equip", cards }
          }
        },
        prompt = "#lingling__qiongqing-choose",
        cancelable = false,
      })
      local target = room:askToChoosePlayers(player, {
        targets = room.alive_players,
        min_num = 1,
        max_num = 1,
        skill_name = qiongqing.name,
        prompt = "#lingling__qiongqing-target:::" .. Fk:getCardById(card).name,
        cancelable = false,
      })[1]
      room:setCardMark(Fk:getCardById(card), MarkEnum.DestructIntoDiscard, 1)
      room:moveCardTo(card, Card.PlayerHand, target, fk.ReasonJustMove, qiongqing.name, nil, true, player)
      if player.dead or target.dead then return end
      if not target:isNude() and target ~= player then
        local cid = room:askToCards(target, {
          min_num = 1,
          max_num = 1,
          include_equip = true,
          skill_name = qiongqing.name,
          prompt = "#lingling__qiongqing-give::" .. player.id,
          cancelable = false,
        })
        room:moveCardTo(cid, Card.PlayerHand, player, fk.ReasonGive, qiongqing.name, nil, false, target)
      end
    end
  end,
})

return qiongqing
